*********************
* Main Paper Exhibits *
*********************

* Table 1: Impact of Treatment on IPV
* Table 2: Impact of Treatment on Boys' Outcomes
* Table 3: Implementation of Goal Setting Strategies
* Table 4: Impact of Treatment on Change in Partnership

clear
clear matrix
estimates clear
eststo clear
set more off
cap log close

cd "$directory"


global controls_bl = "hghst_grade_bl own_house_bl momtalk_sex_never_bl age_bl "
global ipv3b = "ipv_often ipv_12mo"

**************************************************
* Table 1: Impact of Treatment on IPV
**************************************************

#d;
local sample_num = 1;
foreach sample in ""
                 " & partner_past2yr_bl==1 & had_sex_bl==1"
                 " & (grs_anyboy_enr==1 | treat_boys==0)"
                  {;

    #delimit;
    use "data/girls-replication-data.dta", clear;

    keep if panel_bal==2&endline==1 `sample';

    #d ;
    foreach x in $controls_bl {;
        qui sum `x' ;
        replace `x' = `x' - r(mean);
    };

    foreach out in $ipv3b {;
        areg `out' treat_boys treat_goal treat_supply 
                treat_boys_goal treat_supply_goal 
                    $controls_bl `out'_bl, cluster(clubs) abs(region);
        
        if `sample_num' == 3 {;
            sum `out' if control_group==1&treat_goal==0&nameboysex_bl==1 ;
            estadd scalar outmean = r(mean);
            estadd scalar outsd = r(sd);
        };
        else {;
            sum `out' if control_group==1&treat_goal==0 ;
            estadd scalar outmean = r(mean);
            estadd scalar outsd = r(sd);
        };

        estimates store `out'_`sample_num';
    };

    local ++sample_num;
};

*Transposed Table;
esttab ipv_often_1 ipv_12mo_1 ipv_often_2 ipv_12mo_2 ipv_often_3 ipv_12mo_3, se keep (treat_boys treat_goal treat_supply 
	treat_boys_goal treat_supply_goal)
	stats(outmean N);

*Matrix Extraction;
matrix c =r(coefs);
matrix S =r(stats);

mat list c;

matrix mean0 = S[1,1..6]; /*Stats matrix of means*/;
matrix N = S[2,1..6]; /*sample size*/;
matrix mean1 = mean0\N;

label variable ipv_12mo "IPV in past year";
label variable ipv_often "IPV often";


*Table for the "x Post";
local rnames: rownames c;
local models: coleq c;
local models: list uniq models;

*The treatment coefficients;
local i 0;
foreach name of local rnames {;
    local ++i;
    local j 0;
    capture matrix drop b;
    capture matrix drop se;
    capture matrix drop p;
    foreach model of local models {;
        local ++j;
        matrix tmp = c[`i',3*`j'-2];
        if tmp[1,1]<. {;
        matrix colnames tmp = `model';
        matrix b=nullmat(b), tmp;
        matrix tmp[1,1]=c[`i',3*`j'-1];
        matrix se = nullmat(se), tmp;
        matrix tmp[1,1]=c[`i',3*`j'];
        matrix p = nullmat(p), tmp;
    };
};
ereturn post b;
quietly estadd matrix se;
quietly estadd matrix p;

*mat li p;
mat li se;

eststo `name';
};

*Mean and observations;
local mnames : rownames mean1;
local i 0;
foreach name of local mnames {;
local ++i;
local j 0;
capture matrix drop b;
foreach model of local models {;
local ++j;
matrix tmp = mean1[`i', `j'];
matrix colnames tmp = `model';
matrix b = nullmat(b), tmp;
};
ereturn post b;
eststo `name';
};

#d;
esttab using "output/Table_1.tex", se  
mtitles("Boys" "Goal" "Supply" "BoysxGoal" "SupplyxGoal"
		"Mean" "Observations")  
		title("Impact of Treatments on Intimate Partner Violence (IPV)") 
star(* 0.10 ** 0.05 *** 0.01) cells(b(star fmt(3)) se(par fmt(3)) p(par([ ]) fmt(3)))
label style(tex) noconstant noobs replace;

eststo clear;



**************************************************
* Table 2: Impact of Treatment on Boys' Outcomes
**************************************************


#delimit;


global outcomes = "viol_indexbg knowlindex";	   
			   
global partners ="partner_indexbg";	

global controls_boys_bl "hghst_grade_bl own_house_bl dadtalk_sex_never_bl age_bl";	


local sample_num = 1;
foreach sample in "" " & (grs_enroll==1 | treat_boys==0)" {;
    use "data/boys-replication-data.dta", replace;

    keep if panel_bal==2&endline==1 `sample';

    #d ;
    foreach x in $controls_boys_bl {;
        qui sum `x';
        replace `x' = `x' - r(mean);
    };

    foreach out in knowlindex partner_indexbg viol_indexbg {;

    areg `out' treat_boys treat_goal treat_supply treat_boys_goal 
            treat_supply_goal $controls_boys_bl `out'_bl, abs(region) cluster(girlid);
        
        sum `out' if control_group==1&treat_goal==0;
        estadd scalar outmean = r(mean);
        
        estimates store `out'_`sample_num';
    };

    local ++sample_num;
};

#d;
*Transposed Table;
esttab knowlindex_1 partner_indexbg_1 viol_indexbg_1 knowlindex_2 partner_indexbg_2 viol_indexbg_2, se keep (treat_boys treat_goal treat_supply 
	treat_boys_goal treat_supply_goal)
	stats(outmean N);

*Matrix Extraction;
#d;
matrix c =r(coefs);
matrix S =r(stats);

matrix mean0 = S[1,1..6]; /*Stats matrix of means*/;
matrix N = S[2,1..6]; /*sample size*/;
matrix mean1 = mean0\N;


lab var knowlindex "Risk Perceptions index";
lab var partner_indexbg "Sexual activity Index";
lab var viol_indexbg "Violence attitudes Index";

*Table for the "x Post";
#d;
local rnames: rownames c;
local models: coleq c;
local models: list uniq models;

*The treatment coefficients;

local i 0;
foreach name of local rnames {;
local ++i;
local j 0;
capture matrix drop b;
capture matrix drop se;
capture matrix drop p;
foreach model of local models {;
local ++j;
matrix tmp = c[`i',3*`j'-2];
if tmp[1,1]<. {;
matrix colnames tmp = `model';
matrix b=nullmat(b), tmp;
matrix tmp[1,1]=c[`i',3*`j'-1];
matrix se = nullmat(se), tmp;
matrix tmp[1,1]=c[`i',3*`j'];
matrix p = nullmat(p), tmp;
};
};
ereturn post b;
quietly estadd matrix se;
quietly estadd matrix p;
eststo `name';
};
;

*Mean and observations;
local mnames : rownames mean1;
local i 0;
foreach name of local mnames {;
local ++i;
local j 0;
capture matrix drop b;
foreach model of local models {;
local ++j;
matrix tmp = mean1[`i', `j'];
matrix colnames tmp = `model';
matrix b = nullmat(b), tmp;
};
ereturn post b;
eststo `name';
};

#d;
esttab using "output/Table_2.tex", se  
mtitles("Boys" "Goal" "Supply" "BoysxGoal" "SupplyxGoal"  
		"Mean" "Observations")  
		title("Impact of Treatments on Male IPV and SRH Attitudes (Male Data)") 
star(* 0.10 ** 0.05 *** 0.01) cells(b(star fmt(3)) se(par fmt(3)) p(par([ ]) fmt(3)))
label style(tex) noconstant noobs replace;



eststo clear;
estimates clear;


**************************************************;
* Table 3: Implementation of Goal Setting Strategies;
**************************************************;

#d cr

use "data/girls-replication-data.dta", clear



foreach out in abstain1 no_partner usecondom1 {
	
	areg `out' goalabst goalcond goaloth  if endline==1&panel_bal==2, cluster(clubs) abs(region)
	sum `out' if endline==1 & panel_bal==2 & treat_goal==0
	estadd scalar outmean=r(mean)
	estimates store br_`out'
	
}

lab var goalabst "Goal to abstain"
lab var goalcond "Goal to use condom"
lab var goaloth "Other goal"

#d;
esttab br_* using "output/Table_3.tex",
title("Implementation of Strategies Achieved (branch FE)") star(* 0.10 ** 0.05 *** 0.01)
collabels(none) cells(b(star fmt(3)) se(par fmt(3))) label style(tab) noconstant replace
stats(outmean N, fmt(3 0) label("Endline No Goal Mean" "Observations"));

estimates clear;


**************************************************
* Table 4: Impact of Treatment on Change in Partnership *
**************************************************

#d;
global currently_partners = "old";

global controlsN = "hghst_grade own_house momtalk_sex_never age"; 

use "data/girls-replication-data.dta", clear;

 keep if endline==1&panel_bal==2;
#d;
global balance_varorder ipv_often ipv_12mo ipv_often_active ipv_12mo_active
                        had_sex has_partner partner_past2yr total_partners 
                        momtalk_sex_never age hghst_grade married_coh own_house;
global controlsbl = "hghst_grade_bl own_house_bl momtalk_sex_never_bl age_bl";

areg prtnr_index treat_boys treat_goal treat_supply treat_boys_goal
    treat_supply_goal $controlsbl prtnr_index_bl, cluster(clubs) abs(region);
    
test treat_boys = treat_goal;

sum prtnr_index if control_group==1&endline==1 & panel_bal==2&treat_goal==0;
estadd scalar outmean = r(mean);

estimates store prtnr_index;


#d;
global currently_partners = "old";

global controlsN = "hghst_grade own_house momtalk_sex_never age"; 

local sample_num = 1;
foreach sample in ""
                 "keep if ipv_12mo_bl==1"
                 "keep if ipv_12mo_bl==0" {;

    use "data/girls-partners-replication-data.dta", clear;

    

    `sample';

    global controlsbl = "hghst_grade_bl own_house_bl momtalk_sex_never_bl age_bl";


    foreach out in $currently_partners {;

    areg `out' treat_boys treat_goal treat_supply treat_boys_goal
        treat_supply_goal $controlsbl, cluster(clubs) abs(region);

        sum `out' if control_group==1&endline==1 & panel_bal==2&treat_goal==0;
        estadd scalar outmean = r(mean);
        
        estimates store `out'_`sample_num';

    };

    local ++sample_num;
};


esttab prtnr_index old_1 old_2 old_3, se  
	keep (treat_boys treat_goal treat_supply treat_boys_goal
	treat_supply_goal) stats(outmean N pvalue);

*Matrix Extraction;
matrix c =r(coefs);
matrix S =r(stats);


matrix mean0 = S[1,1..4]; 
matrix N = S[2,1..4]; 
matrix mean1 = mean0\N; 

lab var old "With same partner as baseline";


*Table for the "x Post";
local rnames: rownames c;
local models: coleq c;
local models: list uniq models;


*The treatment coefficients;
local i 0;
foreach name of local rnames {;
local ++i;
local j 0;
capture matrix drop b;
capture matrix drop se;
capture matrix drop p;
foreach model of local models {;
local ++j;
matrix tmp = c[`i',3*`j'-2];
if tmp[1,1]<. {;
matrix colnames tmp = `model';
matrix b=nullmat(b), tmp;
matrix tmp[1,1]=c[`i',3*`j'-1];
matrix se = nullmat(se), tmp;
matrix tmp[1,1]=c[`i',3*`j'];
matrix p = nullmat(p), tmp;
};
};
ereturn post b;
quietly estadd matrix se;
quietly estadd matrix p;
eststo `name';
};
;


*Mean and observations;
local mnames : rownames mean1;
local i 0;
foreach name of local mnames {;
local ++i;
local j 0;
capture matrix drop b;
foreach model of local models {;
local ++j;
matrix tmp = mean1[`i', `j'];
matrix colnames tmp = `model';
matrix b = nullmat(b), tmp;
};
ereturn post b;
eststo `name';
};

#d;
esttab using "output/Table_4.tex", se  
mtitles("Boys" "Goal" "MST" "BoysxGoal" "MSTxGoal"
		"Control Mean" "Observations")  
		title("Impact of Treatments on Partner Churn and Quality of Sex Partners") 
star(* 0.10 ** 0.05 *** 0.01) cells(b(star fmt(3)) se(par fmt(3)) p(par([ ]) fmt(3)))
label style(tex) noconstant noobs replace;


eststo clear;
